package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocSponsorialDetailDao;
import com.irdstudio.cdp.pboc.service.domain.PbocSponsorialDetail;
import com.irdstudio.cdp.pboc.service.facade.PbocSponsorialDetailService;
import com.irdstudio.cdp.pboc.service.vo.PbocSponsorialDetailVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 保证人代偿信息				<p>
 * @author ligm
 * @date 2018-12-27
 */
@Service("pbocSponsorialDetailService")
public class PbocSponsorialDetailServiceImpl implements PbocSponsorialDetailService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocSponsorialDetailServiceImpl.class);

	@Autowired
	private PbocSponsorialDetailDao pbocSponsorialDetailDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocSponsorialDetail(PbocSponsorialDetailVO inPbocSponsorialDetailVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocSponsorialDetailVo.toString());
		int num = 0;
		try {
			PbocSponsorialDetail pbocSponsorialDetail = new PbocSponsorialDetail();
			beanCopy(inPbocSponsorialDetailVo, pbocSponsorialDetail);
			num = pbocSponsorialDetailDao.insertPbocSponsorialDetail(pbocSponsorialDetail);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocSponsorialDetailVO inPbocSponsorialDetailVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocSponsorialDetailVo);
		int num = 0;
		try {
			PbocSponsorialDetail pbocSponsorialDetail = new PbocSponsorialDetail();
			beanCopy(inPbocSponsorialDetailVo, pbocSponsorialDetail);
			num = pbocSponsorialDetailDao.deleteByPk(pbocSponsorialDetail);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocSponsorialDetailVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocSponsorialDetailVO inPbocSponsorialDetailVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocSponsorialDetailVo.toString());
		int num = 0;
		try {
			PbocSponsorialDetail pbocSponsorialDetail = new PbocSponsorialDetail();
			beanCopy(inPbocSponsorialDetailVo, pbocSponsorialDetail);
			num = pbocSponsorialDetailDao.updateByPk(pbocSponsorialDetail);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocSponsorialDetailVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocSponsorialDetailVO queryByPk(PbocSponsorialDetailVO inPbocSponsorialDetailVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocSponsorialDetailVo);
		try {
			PbocSponsorialDetail queryPbocSponsorialDetail = new PbocSponsorialDetail();
			beanCopy(inPbocSponsorialDetailVo, queryPbocSponsorialDetail);
			PbocSponsorialDetail queryRslPbocSponsorialDetail = pbocSponsorialDetailDao.queryByPk(queryPbocSponsorialDetail);
			if (Objects.nonNull(queryRslPbocSponsorialDetail)) {
				PbocSponsorialDetailVO outPbocSponsorialDetailVo = beanCopy(queryRslPbocSponsorialDetail, new PbocSponsorialDetailVO());
				logger.debug("当前查询结果为:"+ outPbocSponsorialDetailVo.toString());
				return outPbocSponsorialDetailVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocSponsorialDetailVO> queryAllOwner(PbocSponsorialDetailVO pbocSponsorialDetailVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocSponsorialDetailVO> list = null;
		try {
			List<PbocSponsorialDetail> pbocSponsorialDetails = pbocSponsorialDetailDao.queryAllOwnerByPage(pbocSponsorialDetailVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocSponsorialDetails.size());
			pageSet(pbocSponsorialDetails, pbocSponsorialDetailVo);
			list = (List<PbocSponsorialDetailVO>) beansCopy(pbocSponsorialDetails, PbocSponsorialDetailVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocSponsorialDetailVO> queryAllCurrOrg(PbocSponsorialDetailVO pbocSponsorialDetailVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocSponsorialDetail> pbocSponsorialDetails = pbocSponsorialDetailDao.queryAllCurrOrgByPage(pbocSponsorialDetailVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocSponsorialDetails.size());
		List<PbocSponsorialDetailVO> list = null;
		try {
			pageSet(pbocSponsorialDetails, pbocSponsorialDetailVo);
			list = (List<PbocSponsorialDetailVO>) beansCopy(pbocSponsorialDetails, PbocSponsorialDetailVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocSponsorialDetailVO> queryAllCurrDownOrg(PbocSponsorialDetailVO pbocSponsorialDetailVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocSponsorialDetail> pbocSponsorialDetails = pbocSponsorialDetailDao.queryAllCurrDownOrgByPage(pbocSponsorialDetailVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocSponsorialDetails.size());
		List<PbocSponsorialDetailVO> list = null;
		try {
			pageSet(pbocSponsorialDetails, pbocSponsorialDetailVo);
			list = (List<PbocSponsorialDetailVO>) beansCopy(pbocSponsorialDetails, PbocSponsorialDetailVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}

	/**
	 * 通过fId查询: <br>
	 * 0.1:caoxin:2019/5/9 16:10: <br>
	 * @author caoxin
	 * @return
	 * @since 2019/5/9 16:10
	 * @date 2019/5/9 16:10
	 * @version 0.1
	 */
//	@author:liuty
//	@date:2019/10/17
//	涉及产品:税e贷
//	功能:通过fId查询
//	原因:增量投产只投了接口没投实现，编译报错因此注释，不影响实际业务
//	@SuppressWarnings("unchecked")
//	public List<PbocSponsorialDetailVO> queryByFId(PbocSponsorialDetailVO pbocSponsorialDetailVO) throws Exception {
//
//		logger.debug("当前查询保证人代偿信息为:");
//		List<PbocSponsorialDetail> pbocSponsorialDetails = pbocSponsorialDetailDao.queryByFId(pbocSponsorialDetailVO);
//		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:" + pbocSponsorialDetails.size());
//		List<PbocSponsorialDetailVO> list = null;
//		try {
//			pageSet(pbocSponsorialDetails, pbocSponsorialDetailVO);
//			list = (List<PbocSponsorialDetailVO>) beansCopy(pbocSponsorialDetails, PbocSponsorialDetailVO.class);
//		} catch (Exception e) {
//			logger.error("数据转换出现异常!", e);
//			throw e;
//		}
//
//		return list;
//
//	}
}
